package com.muchfish.webflux.api;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RequestPredicates.POST;

@Configuration
public class MyRouterConfig {

    @Bean
    public RouterFunction<ServerResponse> myRoutes(MyHandler handler) {
        return RouterFunctions.route(GET("/api/resource/{id}"), handler::handleResource)
                .andRoute(POST("/api/resource"), handler::createResource);
    }
}
